package com.htl.reflection.test;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Properties;

public class Reflection__test {

    private static Properties properties;

    static {
        properties = new Properties();
        try {
//            properties.load(new FileInputStream("D:\\Project\\IDEA_project\\java_note\\src\\com\\htl\\reflection\\bean.properties"));
            properties.load(new FileInputStream(System.getProperty("user.dir")+"/src/com/htl/reflection/bean.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception{
//        Dog dog = new Dog();
//        dog.setId(1);
//        dog.setName("旺财");
//        System.out.println(dog);

        // 获取目标类名
        String bean = properties.getProperty("bean");
        // 根据目标类名获取目标类所对应的Class对象（描述结构）
        Class clazz = Class.forName(bean);
        // 获取构造器
        Constructor constructor = clazz.getConstructor(null);
        // 通过构造器创建对象
        System.out.println(constructor.newInstance(null));

    }
}
